<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>766-登录</title>
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
		<link rel="icon" href="${base}/favicon.ico" type="image/x-icon" />
		<link href="${base}/resources/mobile/css/style.css" rel="stylesheet" type="text/css" />
		<link href="${base}/resources/shop/css/login.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div class="login_header content">
			<a href="${base}/pad/index.jhtml">
				<img src="${base}/resources/mobile/images/logo_b.png" alt="766" class="logo"/>
			</a>
			<span class="main_color">欢迎登陆</span>
			<div class="right">
				<a href="${base}/pad/index.jhtml">返回首页</a>
				<a href="${base}/pad/register/index.jhtml">立即注册</a>
			</div>
		</div>
		<div class="login_con content clearfix">
			<a class="left">
				<img src="${base}/resources/mobile/images/product_07.png"/>
			</a>
			<div class="right">
				<form id="loginForm" action="${base}/pad/login/submit.jhtml" method="post">
					<h2>账户登录</h2>
					<ul class="login_list">
						<li class="inputText">
							<label for="username"></label>
							<div>
								<input type="text" id="username" name="username" placeholder="请输入用户名/手机号" maxlength="50"/>
							</div>
						</li>
						<li class="inputText">
							<label for="password"></label>
							<div>
								<input type="password" id="password" name="password" placeholder="请输入密码"/>
							</div>
						</li>
						<li>
							<span class="left">
								<input type="checkbox" name="isRememberUsername" id="isRememberUsername" value=""/>
								<label for="isRememberUsername">记住用户名</label>
							</span>
						</li>
						<li>
							<button type="submit" class="font-bold login_btn" id="loginBtn">登录</button>
						</li>
						<li class="register_prompt"><span>还没有注册？</span><a href="${base}/pad/register/index.jhtml" class="main_color">立即注册!</a></li>
					</ul>
				</form>
			</div>
		</div>
		[#include "/pad/include/footer.ftl" /]
	</body>
<script type="text/javascript" src="${base}/resources/public/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/jsbn.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/prng4.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/rng.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/rsa.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/base64.js"></script>
	<script type="text/javascript">
		$().ready(function() {
		
			var $loginForm = $("#loginForm");
			var $username = $("#username");
			var $password = $("#password");
			var $isRememberUsername = $("#isRememberUsername");
			var $submit = $("#loginBtn");
			
			// 记住用户名
			if (getCookie("memberUsername") != null) {
				$isRememberUsername.prop("checked", true);
				$username.val(getCookie("memberUsername"));
				$password.focus();
			} else {
				$isRememberUsername.prop("checked", false);
				$username.focus();
			}
			
			// 表单验证、记住用户名
			$loginForm.validate({
				rules: {
					username: "required",
					password: "required"
				},
				messages: {
					username: {
						required: "${message("admin.validate.required")}"
					},
					password: {
						required: "${message("admin.validate.required")}"
					}
				},
				submitHandler: function(form) {
					$.ajax({
						url: "${base}/common/public_key.jhtml",
						type: "GET",
						dataType: "json",
						cache: false,
						beforeSend: function() {
							$submit.prop("disabled", true);
						},
						success: function(data) {
							var rsaKey = new RSAKey();
							rsaKey.setPublic(b64tohex(data.modulus), b64tohex(data.exponent));
							var enPassword = hex2b64(rsaKey.encrypt($password.val()));
							$.ajax({
								url: $loginForm.attr("action"),
								type: "POST",
								data: {
									username: $username.val(),
									enPassword: enPassword
								},
								dataType: "json",
								cache: false,
								success: function(message) {
									if ($isRememberUsername.prop("checked")) {
										addCookie("memberUsername", $username.val(), {expires: 7 * 24 * 60 * 60});
									} else {
										removeCookie("memberUsername");
									}
									if (message.type == "success") {
										var url = location.search; //获取url中"?"符后的字串     
									    var theRequest = new Object();     
									    if (url.indexOf("?") != -1) {     
									        var str = url.substr(1);        
									        strs = str.split("&"); 
									        for(var i = 0; i < strs.length; i ++) {    
									            theRequest[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]); 
									        } 
									    } 
										if(theRequest.redirectUrl){
											location.href = theRequest.redirectUrl;
										}else{
											location.href = "${base}/pad/index.jhtml";
										}
									} else {
										$.message(message);
									}
								}
							});
						},
						complete: function() {
							$submit.prop("disabled", false);
						}
					});
				}
			});
		
		});
	</script>
</html>
